//
//  PlayVideoViewController.m
//  Products_B
//
//  Created by lanou on 16/5/29.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "PlayVideoViewController.h"

@interface PlayVideoViewController ()

@property (nonatomic ,strong) AVPlayer *player;

@end

@implementation PlayVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // 播放视频必须创建AVPlayerItem对象
    
    //第一步：
    AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:[NSURL URLWithString:_videoURL]];
    // 第二步：
    self.player = [[AVPlayer alloc] initWithPlayerItem:item];
    [self.player replaceCurrentItemWithPlayerItem:item];
    // 第三步:
    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_player];
    layer.videoGravity = AVLayerVideoGravityResize;
    layer.frame = [UIScreen mainScreen].bounds;
    layer.backgroundColor = [UIColor cyanColor].CGColor;
    [self.view.layer addSublayer:layer];
    // 播放
    [self.player play];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
